package com.chentongwei.spring.annotation.conditional.config;

import com.chentongwei.spring.annotation.conditional.condition.LinuxCondition;
import com.chentongwei.spring.annotation.conditional.condition.WindowsCondition;
import com.chentongwei.spring.annotation.conditional.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @author TongWei.Chen 2018-07-04 10:55:27
 * @Description:
 * @Project spring-annonation
 */
@Configuration
public class MainConfig {

    /**
     * @Conditional({Condition})： 按照一定的条件进行判断，满足条件给容器中注册bean
     *
     * 若是windows系统，则给容器中注册bill
     * 若是linux系统，则给容器中注册linux
     *
     * @return
     */
    @Bean("bill")
    @Conditional({WindowsCondition.class})
    public User user01() {
        return new User("比尔盖茨", 62);
    }

    @Bean("linus")
    @Conditional({LinuxCondition.class})
    public User user02() {
        return new User("Linus", 45);
    }
}
